<template>
  <a-layout>
    <a-layout-content style="height: calc(100vh - 88px); padding: 2px">
      <VxeBasicTable ref="TableRef" v-bind="options">
        <template #toolbar_buttons>
          <ToolBtn
            :filter-call="handleOpenFilter"
            :create-call="handleDelete"
            :show-export="false"
            :show-import="false"
            :show-delete="false"
            :show-filter="false"
          />
        </template>
      </VxeBasicTable>
    </a-layout-content>
    <TableFilter
      ref="FilterRef"
      @done="reload"
      v-model:visible="ifSHowFilter"
      :filter-cols="Columns"
    />
  </a-layout>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { message } from 'ant-design-vue/es';
  import { messageLoading } from 'ele-admin-pro/es';
  import { getVisLogPageList, clearVisLog } from '@/api/system/log';
  import { useConfig } from './config';

  const { TableRef, FilterRef, Columns, TableFilter, ToolBtn, options } =
    useConfig(getVisLogPageList);

  const ifSHowFilter = ref(false);

  /* 刷新表格 */
  const reload = () => {
    TableRef.value?.commitProxy('query');
  };

  const handleOpenFilter = () => {
    ifSHowFilter.value = true;
  };

  /* 删除 */
  const handleDelete = () => {
    const hide = messageLoading('请求中..', 0);
    clearVisLog()
      .then((msg) => {
        hide();
        message.success(msg);
        reload();
      })
      .catch((e) => {
        hide();
        message.error(e.message);
      });
  };
</script>

<script lang="ts">
  export default {
    name: 'VislogManagement'
  };
</script>
